#coding=utf-8
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
cap = DesiredCapabilities()
def visit(driver):
    driver.maximize_window()
    driver.get("https://www.baidu.com")  # 火狐浏览器必须要https
    import time
    time.sleep(5)
    driver.quit()
th = []
hosts = {
    #通过zalenium方式
    #'http://172.19.0.5:40002/wd/hub': 'firefox',
    # 'http://172.19.0.3:40000/wd/hub': 'chrome',
    #'http://172.19.0.4:40001/wd/hub': 'chrome',
    #'http://172.19.0.6:40003/wd/hub': 'chrome'
    #通过zselenium grid方式
    # 'http://192.168.1.129:5001/wd/hub': 'chrome'
    #通过Selenoid 方式
    # 'http://192.168.1.234:14444/wd/hub': 'firefox'
    # 报错：Message: Unable to find a matching set of capabilities（通过升级火狐到最新版本）# 火狐浏览器驱动版本要匹配
    'http://192.168.1.234:14444/wd/hub': 'firefox'
}
# dcp = DesiredCapabilities()
for host, browser in hosts.items():
    from selenium.webdriver import Remote
    from datetime import datetime
    time = datetime.now()
    now = time.strftime('%Y-%m-%d  %H-%M-%S')
    driver = Remote(
        command_executor=host,
        desired_capabilities = {
            # "platform": "ANY",
            # 实时查看
            'enableVNC': True,
            "browserName": browser,
            # 'enableVideo': True,
            # 'videoName': "videoName"+ now  # 注意，需要最新版selenoid/video-recorder:latest-release
            # "marionette": True,
            # "acceptInsecureCerts": True,
            'marionette': False  # marionette是python客户端允许运行远程控制基于gecko的浏览器或设备运行一个marionette服务器，包括桌面firefox和firefox os。该参数为firefox特用。




    }
    )
    import threading
    th.append(threading.Thread(target=visit, args=[driver]))

for t in th:
    t.start()